package com.auction.controller.admin;

import com.auction.dto.AuctionPageQueryDTO;
import com.auction.pojo.PageResult;
import com.auction.pojo.Result;
import com.auction.service.AuctionService;
import com.auction.vo.AuctionVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminAuctionController")
@RequestMapping("/admin/auction")
public class AuctionController {

    @Autowired
    private AuctionService auctionService;

    /**
     * 分页查询拍卖品列表
     * 
     * @param auctionPageQueryDTO 分页查询条件
     * @return 拍卖品分页列表
     */
    @GetMapping("/page")
    public Result<PageResult> page(AuctionPageQueryDTO auctionPageQueryDTO) {
        log.info("管理员分页查询拍卖品列表：{}", auctionPageQueryDTO);
        PageResult pageResult = auctionService.page(auctionPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 获取拍卖品详情
     * 
     * @param id 拍卖品ID
     * @return 拍卖品详情
     */
    @GetMapping("/{id}")
    public Result<AuctionVO> getById(@PathVariable Long id) {
        log.info("管理员获取拍卖品详情：id={}", id);
        AuctionVO auctionVO = auctionService.getByIdVO(id);
        return Result.success(auctionVO);
    }

    /**
     * 审核拍卖品
     * 
     * @param id 拍卖品ID
     * @param status    审核状态（待处理PENDING 激活ACTIVE 已结束FINISHED 已取消CANCELLED）
     * @return 审核结果
     */
    @PutMapping("/{id}/review")
    public Result<Boolean> reviewAuction(
            @PathVariable Long id,
            @RequestParam String status) {

        log.info("审核拍卖品：id={}, 状态={}", id, status);

        boolean result = auctionService.reviewAuction(id, status);
        return Result.success(result);
    }

    /**
     * 获取拍卖品数量
     * @param type
     * @return
     */
    @GetMapping("/category/{type}")
    public Result<Integer> getCountByCategory(@PathVariable Integer type) {
        log.info("获取拍卖品数量：type={}", type);
        Integer count = auctionService.getCountByCategory(type);
        return Result.success(count);
    }
}
